package com.yanqu.road.server.cmd.wingroom;

import com.yanqu.road.entity.wingroom.UserFurnitureSuitData;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wingroom.WingRoomModule;
import com.yanqu.road.server.pb.WingRoomPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2022/2/24 14:21
 */
@Cmd(code = GameProtocol.S_WING_ROOM_FURNITURE_SUIT_LV_UP, desc = "家具套装升级")
public class FurnitureSuitLvUpCmd extends AbstractCommand {
    private int suitType;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WingRoomProto.FurnitureSuitLvUpReqMsg reqMsg = WingRoomProto.FurnitureSuitLvUpReqMsg.parseFrom(packet.getBytes());
        suitType = reqMsg.getSuitType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WingRoomModule.class).furnitureSuitLvUp(suitType);
    }

    @Override
    public void sendData(GamePlayer player) {
        WingRoomProto.FurnitureSuitLvUpRespMsg.Builder respMsg = WingRoomProto.FurnitureSuitLvUpRespMsg.newBuilder();
        respMsg.setRet(ret);
        UserFurnitureSuitData suitData = player.getModule(WingRoomModule.class).getSuitData(suitType);
        respMsg.setSyncSuitData(WingRoomPb.buildFurnitureSuitDataTemp(suitData));
        player.sendPacket(ClientProtocol.U_WING_ROOM_FURNITURE_SUIT_LV_UP, respMsg);
    }
}
